package br.com.fabrica.aid.aid_fabrica.view;

import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import br.com.fabrica.aid.aid_fabrica.business.ColaboradorBC;
import br.com.fabrica.aid.aid_fabrica.domain.Colaborador;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@ViewController
@NextView("./colaborador_edit.xhtml")
@PreviousView("./colaborador_list.xhtml")
public class ColaboradorListMB extends AbstractListPageBean<Colaborador, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private ColaboradorBC cl;

	@Override
	protected List<Colaborador> handleResultList() {
		return this.cl.findAll();
	}

	@Transactional
	public String deleteSelection() {
		boolean delete;
		for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
			Long idcolaborador = iter.next();
			delete = getSelection().get(idcolaborador);

			if (delete) {				
				cl.delete(idcolaborador);
				iter.remove();
			}
		}
		return getPreviousView();
	}

}